# 多线程
from threading import Thread

# 方式1：实现多线程（小脚本常用）
# def func():
#     for i in range(1000):
#         print("func", i)
#
# if __name__ == '__main__':
#     t = Thread(target=func)
#     t.start()
#     for i in range(1000):
#         print("main", i)

# 传参带名称
def func(name):
    for i in range(100):
        print(name, i)

if __name__ == '__main__':
    # 传递的参数必须是元组，只有一个字符串也要用 , 隔开进行区分
    t1 = Thread(target=func, args=("jaychou",))
    t1.start()

    t2 = Thread(target=func, args=("jj",))
    t2.start()

# 方式2：实现多线程（专业常用）
# class MyThread(Thread):
#     def run(self):
#         for i in range(1000):
#             print("MyThread", i)
#
# if __name__ == '__main__':
#     t = MyThread()
#     # 用 t.run()，会变成方法调用，退化为单线程
#     # t.tun()
#     t.start()
#     for i in range(1000):
#         print("main", i)